/**
 *  Copyright (C) 2013  Piotr Szczepa�ski
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package edu.pw.elka.gtsna.test_performance;

import edu.pw.elka.gtsna.centrality.degree.CSemivalueNodeCentrality;
import edu.pw.elka.gtsna.centrality.degree.OVDegreeCentrality;
import edu.pw.elka.gtsna.centrality.degree.SVDegreeCentrality;
import edu.pw.elka.gtsna.community_detection.CommunityStructure;
import edu.pw.elka.gtsna.graph.UndirectedGraph;
import edu.pw.elka.gtsna.graph_creator.TGFCommunityStructureReader;
import edu.pw.elka.gtsna.graph_creator.TGFReader;
import edu.pw.elka.gtsna.ranking.Ranking;
import edu.pw.elka.gtsna.utilities.MathPowers;
import static edu.pw.elka.gtsna.utilities.MathBinomialCoefficient.binomial;

/**
 * @author Piotr Lech Szczepa�ski
 * @author P.Szczepanski@ii.pw.edu.pl 
 *
 */
public class ECAI2014ColaitionalSemivaluesPerformance extends Performer{
	public static void main(String[] args) {
		
		CommunityStructure cs = new CommunityStructure(new TGFCommunityStructureReader("zacharyCS.in"));
		UndirectedGraph g = new UndirectedGraph(new TGFReader("zachary.in"));
		

		
		CSemivalueNodeCentrality OV = new CSemivalueNodeCentrality(g, cs){
			@Override
			protected double f(int node){return 1.0;}

			@Override
			protected double beta(int k) {
				return (double)1/cs.size();
			}

			@Override
			protected double alpha(int l, int coalitionSize) {
				return (double)1/coalitionSize;
			}
			
		};
		MathPowers.precompute(g.getNumOfNodes());
		OV.computeCentrality();
		Ranking<Integer> r1 = new Ranking(OV.getCentralities());
		

		CSemivalueNodeCentrality OBV = new CSemivalueNodeCentrality(g, cs){
			@Override
			protected double f(int node){return 1.0;}

			@Override
			protected double beta(int k) {
				return binomial(cs.size()-1,k)/Math.pow(2,cs.size()-1);
			}

			@Override
			protected double alpha(int l, int coalitionSize) {
				return binomial(coalitionSize-1,l)/Math.pow(2,coalitionSize-1);
			}
			
		};
		MathPowers.precompute(g.getNumOfNodes());
		OBV.computeCentrality();
		Ranking<Integer> r2 = new Ranking(OBV.getCentralities());
		
		
		CSemivalueNodeCentrality SCBV = new CSemivalueNodeCentrality(g, cs){
			@Override
			protected double f(int node){return 1.0;}

			@Override
			protected double beta(int k) {
				return binomial(cs.size()-1,k)/Math.pow(2,cs.size()-1);
			}

			@Override
			protected double alpha(int l, int coalitionSize) {
				return (double)1/coalitionSize;
			}
			
		};
		MathPowers.precompute(g.getNumOfNodes());
		SCBV.computeCentrality();
		Ranking<Integer> r3 = new Ranking(SCBV.getCentralities());
		

		CSemivalueNodeCentrality SCBS = new CSemivalueNodeCentrality(g, cs){
			@Override
			protected double f(int node){return 1.0;}

			@Override
			protected double beta(int k) {
				double p = 0.25;
				return Math.pow(p, k)*Math.pow(1-p, cs.size()-1-k);
			}

			@Override
			protected double alpha(int l, int coalitionSize) {
				return (double)1/coalitionSize;
			}
			
		};
		MathPowers.precompute(g.getNumOfNodes());
		SCBS.computeCentrality();
		Ranking<Integer> r4 = new Ranking(SCBS.getCentralities());
		
		
		
		Ranking.displayRankings(r1,r2,r3,r4);
		
		for (int node: g.getAllNodes()){
			System.out.println(node+" "+g.getDegree(node));
		}
		
	}
}
